package by.alex.dzeshko.facebooksuperclient.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import android.util.Log;
import by.alex.dzeshko.facebooksuperclient.R;

public class Md5 {
	
	private static final String LOG_TAG = "Md5";

	public static String md5(String in) {

		MessageDigest digest;
		try {
			digest = MessageDigest.getInstance("MD5");
			digest.reset();
			digest.update(in.getBytes());
			byte[] a = digest.digest();
			int len = a.length;
			StringBuilder sb = new StringBuilder(len << 1);
			for (int i = 0; i < len; i++) {
				sb.append(Character.forDigit((a[i] & 0xf0) >> 4, 16));
				sb.append(Character.forDigit(a[i] & 0x0f, 16));
			}
			return sb.toString();

		} catch (NoSuchAlgorithmException e) {
			Log.e(LOG_TAG, e.toString());
		}
		return null;

	}

}
